import request from "@/utils/request";
import axios from "axios";
const token = localStorage.getItem("pz_token");

// 获取验证码
export const getCode = (data) => {
  // return request({
  //     url:'/get/code',
  //     method:'post',
  //     data
  // })
  return request.post("/get/code", data);
};

// 验证码验证 注册用户
export const userAuthentication = (data) => {
  return request.post("/user/authentication", data);
};

// 登录
export const getLogin = (data) => {
  return request.post("/login", data);
};



// 菜单权限数据
export const userGetMenu = () => {
  return request.get("/user/getmenu");
};

// 菜单权限修改
export const userSetMenu = (data) => {
  return request.post("/user/setmenu", data);
};

// 菜单权限列表
// export const menuList = (params)=>{
//   return request.get('/menu/list',params)
// }


export async function menuList(params) {
  try {
    const config = {
      headers: {
        'X-Custom-Header': 'foobar',
        "x-token": token
      },
      params
    }
    const response = await axios.get(" https://v3pz.itndedu.com/v3pz/menu/list", config);
    console.log("GET menuList 请求响应数据:", response.data);
    return response.data;
  } catch (error) {
    handleError(error);
    throw error;
  }
}


// 账号管理列表
// export const getAdmin = (params) => {
//   return request.get("/auth/admin", params);
// };


export const getAdmin = async (params) => {
  try {
    const config = {
      headers: {
        'X-Custom-Header': 'foobar',
        "x-token": token
      },
      params
    }
    const response = await axios.get("https://v3pz.itndedu.com/v3pz/auth/admin", config);
    console.log("GET getAdmin 请求响应数据:", response.data);
    return response.data;
  } catch (error) {
    handleError(error);
    throw error;
  }
}


// 权限下拉列表
export const menuSelectList = (params) => {
  return request.get("/menu/selectlist" , params);
};

// 用户信息修改
export const updateUser = (data) => {
  return request.post("/update/user", data);
};

// 用户菜单权限
export const menuPermissions = () => {
  return request.get("/menu/permissions");
};

 




/*
// GET 请求示例
async function getRequest() {
    try {
        const response = await axios.get('https://api.example.com/data');
        console.log('GET 请求响应数据:', response.data);
    } catch (error) {
        handleError(error);
    }
}

// POST 请求示例
async function postRequest() {
    try {
        const data = {
            name: 'John Doe',
            age: 30
        };
        const response = await axios.post('https://api.example.com/submit', data);
        console.log('POST 请求响应数据:', response.data);
    } catch (error) {
        handleError(error);
    }
}
*/
